package com.gexiaobao.pigeon.ui.adapter

import android.widget.LinearLayout
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.TBodyData
import com.gexiaobao.pigeon.databinding.ItemNowGroupBinding

/**
 * @Author      : hxw
 * @Date        : 2024/7/8 15:57
 * @Describe    :
 */
class AdapterNowGroup(data: ArrayList<TBodyData>) :
    BaseQuickAdapter<TBodyData, DataBindBaseViewHolder>(R.layout.item_now_group, data) {

    private var mOnLargeGroupClickListener: OnLargeGroupClickListener? = null
    private var mOnSmallGroupClickListener: OnSmallGroupClickListener? = null

    override fun convert(holder: DataBindBaseViewHolder, item: TBodyData) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemNowGroupBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        if (holder.layoutPosition % 2 == 0) {
            holder.itemView.setBackgroundColor(ContextCompat.getColor(context, R.color.comm_bg))
        } else {
            holder.itemView.setBackgroundColor(ContextCompat.getColor(context, R.color.white))
        }

        holder.setText(R.id.tvBigGroup,item.A)

        val tvLarge = holder.getView<AppCompatTextView>(R.id.tvBigGroup)
        val tvSmall = holder.getView<AppCompatTextView>(R.id.tvSmallGroup)

        holder.getView<LinearLayout>(R.id.llBigGroup).setOnClickListener {
            mOnLargeGroupClickListener?.onLargeClick(holder.layoutPosition, tvLarge)
        }

        holder.getView<LinearLayout>(R.id.llSmallGroup).setOnClickListener {
            mOnSmallGroupClickListener?.onSmallClick(holder.layoutPosition, tvSmall)
        }
    }

    interface OnLargeGroupClickListener {
        fun onLargeClick(position: Int, view: AppCompatTextView)
    }

    fun setOnLargeClickListener(listener: OnLargeGroupClickListener?) {
        mOnLargeGroupClickListener = listener
    }

    interface OnSmallGroupClickListener {
        fun onSmallClick(position: Int, view: AppCompatTextView)
    }

    fun setOnSmallClickListener(listener: OnSmallGroupClickListener?) {
        mOnSmallGroupClickListener = listener
    }
}